package empox.pos.system.info;

import java.io.File;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CompanyFileListAdapter extends BaseAdapter {
	Context con;

	boolean[] bl = null;

	public CompanyFileListAdapter(Context con) {
		this.con = con;
	}

	public void setValue(boolean[] bl) {
		this.bl = bl;
	}

	public int getCount() {
		if (CompanyFileList.companyfile == null) {
			return 0;
		} else {
			return CompanyFileList.companyfile.size();
		}
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	static class SH {
		CheckBox cb;
		TextView tv1;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		SH sh = new SH();

		if (convertView == null) {
			convertView = new LinearLayout(con);
			((LinearLayout) convertView).setGravity(Gravity.CENTER);

			sh.cb = new CheckBox(con);
			sh.cb.setWidth(100);
			sh.cb.setFocusable(false);
			sh.cb.setEnabled(false);
			((LinearLayout) convertView).addView(sh.cb);

			sh.tv1 = new TextView(con);
			sh.tv1.setWidth(400);
			sh.tv1.setHeight(50);
			sh.tv1.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.tv1);
			sh.tv1.setTextColor(0xff57290a);

			convertView.setTag(sh);
		} else {
			sh = (SH) convertView.getTag();
		}

		File file = CompanyFileList.companyfile.get(position);

		sh.cb.setChecked(bl[position]);
		sh.tv1.setText(file.toString());

		return convertView;
	}

}
